
package com.tuo51.core.repositories;

import com.tuo51.core.domain.pay.OrgWalletWithdrawRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface WalletWithdrawalRepository extends JpaRepository<OrgWalletWithdrawRecord, String>, JpaSpecificationExecutor<OrgWalletWithdrawRecord> {


    @Query(nativeQuery = true,value = "SELECT  sum(apply_withdrawal) as totalWithdrawal FROM wallet_withdrawal  where examine_status=1 and pay_status=0")
    Integer fundTotalWithdrawStatistics();

    @Query(nativeQuery = true,value = "SELECT  sum(apply_withdrawal) as successWithdrawal FROM wallet_withdrawal  where examine_status=1 and pay_status=0")
    Integer fundSuccessWithdrawStatistics();

    @Query(nativeQuery = true,value = "SELECT  sum(apply_withdrawal) as waitWithdrawal FROM wallet_withdrawal  where examine_status=1 and pay_status=1")
    Integer fundWaitWithdrawStatistics();

    @Query(nativeQuery = true,value = "SELECT  sum(apply_withdrawal) as cancelWithdrawal FROM wallet_withdrawal  where  pay_status=2")
    Integer fundCancelWithdrawStatistics();

    @Query(nativeQuery = true,value = "SELECT * from wallet_withdrawal w where w.creator_id = ?1 and w.withdraw_way = 1 group by w.withdraw_account order by w.create_time desc")
    List<OrgWalletWithdrawRecord> allAlipayRecordsByUser(Long userId);

    @Query(nativeQuery = true,value = "SELECT * from wallet_withdrawal w where w.creator_id = ?1 and w.withdraw_way = 0 group by w.bank_number order by w.create_time desc")
    List<OrgWalletWithdrawRecord> allBankRecordsByUser(Long userId);
}
